<template>
  <div class="aside">
    <el-tree
      :props="treeProps"
      :load="loadTreeNode"
      lazy />
  </div>
</template>
<script>
import Mixin from '@/assets/mixin'
export default {
  name: 'Aside',
  mixins: [Mixin],
  doNotInit: true,
  data() {
    return {
      activeMenu: 'demo',
      treeProps: {
        label: 'name',
        children: 'childs',
        isLeaf: 'leaf'
      }
    }
  },
  methods: {
    toIndex: function() {
      this.$router.push('/')
      // this.$store.commit('setActiveMenu', menu.code)
    },
    menuClick: function(menu) {
      this.setLocalData('activeMenu', menu.code, 'setActiveMenu')
      this.$router.push(menu.href)
    },
    init: function() {
      this.activeMenu = this.getLocalData('activeMenu')
        ? this.getLocalData('activeMenu')
        : 'demo'
      this.setLocalData('activeMenu', this.activeMenu, 'setActiveMenu')
    },
    loadTreeNode: function(node, resolve) {
      if (node.level === 0) {
        return resolve([{ name: '数据库' }])
      }
      if (node.level === 1) {
        this.ajaxGet({
          url: '/v3/db/dbDatabase',
          callback: data => {
            return resolve(data.rows)
          }
        })
      }
    }
  }
}
</script>
